package com.example.demo.arithmetic;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * Description: 栈数据结构 先进后出first in last out <br/>
 *
 * @author <br/>;
 * @taskId <br/>
 * @Date 2019/5/14 13:38
 * @Version 1.0
 */
public class IntegerStack {

    /**
     * 可以实现类似栈的出入栈操作
     */
    private Deque<Integer> data = new ArrayDeque<>();

    public Deque<Integer> getData() {
        return data;
    }

    public void setData(Deque<Integer> data) {
        this.data = data;
    }

    /**
     * 入栈 等同addFirst
     *
     * @param e
     */
    public void push(Integer e) {
        data.push(e);
    }

    /**
     * 出栈 removeFirst
     *
     * @return
     */
    public Integer pop() {
        return data.pop();
    }

    /**
     * 获取栈顶元素，不移出 peekFirst()
     *
     * @return
     */
    public Integer peek() {
        return data.peek();
    }

    @Override
    public String toString() {
        return data.toString();
    }

    public static void main(String[] args) {
        IntegerStack stack = new IntegerStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);
        System.out.println(stack.toString());
        System.out.println("取栈顶元素：" + stack.peek());
        System.out.println(stack.toString());
    }
}
